import { createRouter, createWebHistory } from 'vue-router'
import Register from '../components/Register.vue'
import Login from '../components/Login.vue'
// 删除AccountUnfreeze导入
import ResetPassword from '../components/ResetPassword.vue'
import AdminHome from '../components/Administrator/AdminHome.vue'
import SheHome from '../components/she/SheHome.vue'
import UserHome from '../components/dome con/UserHome.vue'
import Home from '../components/Home.vue';
// 修复：将@别名路径改为相对路径
import WxRenyuanHome from '../components/wx renyuan/WxRenyuanHome.vue';
// 使用相对路径替代@别名（解决路径解析问题）
import RepairTasks from '../components/wx renyuan/RepairTasks.vue';
import FaultProgress from '../components/wx renyuan/FaultProgress.vue';
import RobotLogs from '../components/wx renyuan/RobotLogs.vue';
import WxMaintenancePlan from '../components/wx renyuan/MaintenancePlan.vue';
import MaintenanceLogs from '../components/wx renyuan/MaintenanceLogs.vue';
// she文件夹下的组件保持原名
import MaintenancePlan from '../components/she/MaintenancePlan.vue'
import MaintenanceLog from '../components/she/MaintenanceLog.vue'
import WarningAlert from '../components/she/WarningAlert.vue'
import UserQuery from '../components/Administrator/UserQuery.vue';
import AccountApproval from '../components/Administrator/AccountApproval.vue';
import DeviceQuery from '../components/dome con/DeviceQuery.vue';
import AllMaintenancePlans from '../components/she/AllMaintenancePlans.vue';
import RepairUserList from '../components/she/RepairUserList.vue';
// 检查顶部是否有此导入
import AIChat from '../components/dome con/AIChat.vue';
const routes = [
  { path: '/register', name: 'Register', component: Register },
  { path: '/login', name: 'Login', component: Login },
  // 删除AccountUnfreeze路由配置
  { path: '/reset-password', name: 'ResetPassword', component: ResetPassword },
  { path: '/admin', name: 'AdminHome', component: AdminHome },
  {
    path: '/device-admin', name: 'DeviceAdmin', component: SheHome,
    children: [
      { path: 'maintenance-plan', component: MaintenancePlan },
      { path: 'maintenance-log', component: MaintenanceLog },
      { path: 'warning-alert', component: WarningAlert },
      { path: 'device-query', component: DeviceQuery },
      { path: 'all-maintenance-plans', component: AllMaintenancePlans },
      { path: 'repair-user-list', component: RepairUserList } // 新增维修人员列表路由
    ]
  },
  { path: '/she', redirect: '/device-admin' },
  { path: '/wx-renyuan', name: 'WxRenyuan', component: WxRenyuanHome },
  {
    path: '/user-home',
    name: 'userHome',
    component: () => import('@/components/dome con/UserHome.vue'),
    children: [
      {
        path: 'DeviceQuery',
        name: 'deviceQuery',
        component: () => import('@/components/dome con/DeviceQuery.vue')
      },
      // 添加AI聊天路由
      {
        path: 'ai-chat',
        name: 'aiChat',
        component: () => import('@/components/dome con/AIChat.vue')
      }
    ]
  },
  { path: '/Home', name: 'Home', component: Home },
  // 将根路径重定向从Home改为UserHome
  { path: '/', redirect: '/Home' },
  {
    path: '/wx-renyuan',
    name: 'WxRenyuanHome',
    component: WxRenyuanHome,
    children: [
      { path: 'repair-tasks', component: RepairTasks },
      { path: 'fault-progress', component: FaultProgress },
      { path: 'robot-logs', component: RobotLogs },
      // 使用重命名后的组件
      { path: 'maintenance-plan', component: WxMaintenancePlan },
      { path: 'maintenance-logs', component: MaintenanceLogs },
      { path: '', redirect: 'repair-tasks' } // 默认显示报修任务页面
    ],
  },
  {
    path: '/admin-home',
    name: 'AdminHome',
    component: () => import('@/components/Administrator/AdminHome.vue'),
    children: [
      {
        path: 'account-approval',
        name: 'AccountApproval',
        component: () => import('@/components/Administrator/AccountApproval.vue')
      },
      {
        path: 'user-query',
        name: 'UserQuery',
        component: () => import('@/components/Administrator/UserQuery.vue')
      }
    ]
  }
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL), // 使用环境变量中的base url
  // 或者如果是hash模式，确保使用hash模式
  // history: createWebHashHistory(),
  routes
});

export default router;